/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jpa.entities;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.validation.constraints.Digits;

/**
 *
 * @author andreas
 */
@Entity
public class Account implements Serializable {

    private static final long serialVersionUID = 1L;

    @Basic(optional=false)
    @Digits(integer=14, fraction=0)
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Id
    private Long id;

    @Basic(optional=true)
    @OneToOne(mappedBy="Account")
    private Biller biller;

    @Digits(integer=20, fraction=2)
    private BigDecimal balance;

    @OneToMany(mappedBy="account")
    private Set<FinancialStatement> financialStatements = new HashSet<FinancialStatement>();

    @ManyToOne
    private User user;

    @OneToMany(mappedBy="fromAccount")
    private Set<FinancialTransaction> fromTransactions = new HashSet<FinancialTransaction>();

    @OneToMany(mappedBy="toAccount")
    private Set<FinancialTransaction> toTransactions = new HashSet<FinancialTransaction>();

    public BigDecimal getBalance() {
        return balance;
    }

    public void setBalance(BigDecimal balance) {
        this.balance = balance;
    }

    public Biller getBiller() {
        return biller;
    }

    public void setBiller(Biller biller) {
        this.biller = biller;
    }

    public Set<FinancialStatement> getFinancialStatements() {
        return financialStatements;
    }

    public void setFinancialStatements(Set<FinancialStatement> financialStatements) {
        this.financialStatements = financialStatements;
    }

    public Set<FinancialTransaction> getFromTransactions() {
        return fromTransactions;
    }

    public void setFromTransactions(Set<FinancialTransaction> fromTransactions) {
        this.fromTransactions = fromTransactions;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Set<FinancialTransaction> getToTransactions() {
        return toTransactions;
    }

    public void setToTransactions(Set<FinancialTransaction> toTransactions) {
        this.toTransactions = toTransactions;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Account other = (Account) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        if (this.biller != other.biller && (this.biller == null || !this.biller.equals(other.biller))) {
            return false;
        }
        if (this.balance != other.balance && (this.balance == null || !this.balance.equals(other.balance))) {
            return false;
        }
        if (this.financialStatements != other.financialStatements && (this.financialStatements == null || !this.financialStatements.equals(other.financialStatements))) {
            return false;
        }
        if (this.user != other.user && (this.user == null || !this.user.equals(other.user))) {
            return false;
        }
        if (this.fromTransactions != other.fromTransactions && (this.fromTransactions == null || !this.fromTransactions.equals(other.fromTransactions))) {
            return false;
        }
        if (this.toTransactions != other.toTransactions && (this.toTransactions == null || !this.toTransactions.equals(other.toTransactions))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 61 * hash + (this.id != null ? this.id.hashCode() : 0);
        hash = 61 * hash + (this.balance != null ? this.balance.hashCode() : 0);
        return hash;
    }

}
